import pymysql


def main():
    no = int(input("请输入您要更改的部门编号:"))
    loc = input("请输入您要更改的部门地址:")
    conn = pymysql.connect(host='118.31.55.201', port=3306, user='root',
                           passwd='yztdmwrs001029', db='hrs', charset='utf8')
    try:
        with conn.cursor() as cursor:
            result = cursor.execute('update tb_dept set dloc=%s where dno=%s',(loc,no))
            if result == 1:
                print('更新成功!!')
            conn.commit()
    except pymysql.MySQLError as e:
        print(e)
        conn.rollback()
    finally:
        conn.close()


if __name__ == '__main__':
    main()
